#!/usr/bin/env python3
"""
测试统一配置管理器
"""

import sys
import os
import logging
import traceback
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from src.config import get_config

# 配置日志
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s [%(levelname)s] %(message)s',
    datefmt='%Y-%m-%d %H:%M:%S'
)


def test_config():
    """测试配置管理器"""
    logging.info("=== 测试统一配置管理器 ===")
    
    try:
        # 获取配置管理器
        config = get_config()
        logging.info("✅ 配置管理器初始化成功")
        
        # 测试日志配置
        logging_config = config.logging
        logging.info("📝 日志配置:")
        logging.info("  - 级别: %s", logging_config.level)
        logging.info("  - 输出到文件: %s", logging_config.to_file)
        logging.info("  - 文件路径: %s", logging_config.file_path)
        logging.info("  - 控制台输出: %s", logging_config.console_enabled)
        logging.info("  - Tree调试: %s", logging_config.tree_debug_enabled)
        
        # 测试服务发现配置
        service_config = config.service_discovery
        logging.info("🔍 服务发现配置:")
        logging.info("  - 命名空间: %s", service_config.namespace)
        logging.info("  - 标签选择器: %s", service_config.label_selector)
        logging.info("  - 端口名称: %s", service_config.port_name)
        
        # 测试ZMQ配置
        zmq_config = config.zmq
        logging.info("📡 ZMQ配置:")
        logging.info("  - 协议: %s", zmq_config.protocol)
        
        logging.info("✅ 所有配置测试通过!")
        
    except Exception as e:
        logging.error("❌ 配置测试失败: %s", e)
        logging.error(traceback.format_exc())


if __name__ == "__main__":
    test_config()